package com.seeyon.apps.ebs.manager.impl;

import com.seeyon.apps.ebs.manager.AddNewEnumManager;
import com.seeyon.apps.govdoc.manager.GovdocFormManager;
import com.seeyon.cap4.form.service.CAP4FormManager;
import com.seeyon.ctp.common.AppContext;
import com.seeyon.ctp.common.bo.Result;
import com.seeyon.ctp.common.exceptions.BusinessException;
import com.seeyon.ctp.common.po.template.CtpTemplate;
import com.seeyon.ctp.common.template.manager.TemplateManager;
import com.seeyon.ctp.form.bean.FormBean;
import com.seeyon.ctp.form.service.FormManager;
import com.seeyon.ctp.util.annotation.AjaxAccess;


public class AddNewEnumManagerImpl implements AddNewEnumManager {

    private TemplateManager templateManager = (TemplateManager) AppContext.getBean("templateManager");
    private CAP4FormManager cap4FormManager = (CAP4FormManager) AppContext.getBean("cap4FormManager");
    @Override
    @AjaxAccess
    public Result showAddEnumButton(Long templateId) throws BusinessException {
        FormManager formManager = (FormManager) AppContext.getBean("formManager");
        GovdocFormManager govdocFormManager = (GovdocFormManager) AppContext.getBean("govdocFormManager");
        CtpTemplate template = this.templateManager.getCtpTemplate(templateId);
        FormBean edocForm = govdocFormManager.getForm(templateId);
        FormBean form;
        if (template == null&&edocForm==null) {
            return Result.success().setData(false);
        } else if (edocForm==null){
            form = formManager.getFormByFormCode(template);
        }else {
            form = edocForm;
        }
        if (form==null){
            return Result.success().setData(false);
        }
        if ("EBS LETTER-20221218".equals(form.getFormName())) {
            return Result.success().setData(true);
        } else {
            return Result.success().setData(false);
        }
    }
}
